using LocalizationUtils;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

namespace LocalizationUtils.Utils
{
    public class DeleteAdjustArabRightUtil : MonoBehaviour
    {
        private TextMeshProUGUI _textMeshProUGUI;
        private TextMeshPro _textMeshPro;
        private Text _text;

        private void Awake()
        {
            _textMeshProUGUI = GetComponent<TextMeshProUGUI>();
            if (_textMeshProUGUI == null)
            {
                _text = GetComponent<Text>();
                if (_text == null)
                {
                    _textMeshPro = GetComponent<TextMeshPro>();
                }
            }
        }

        public void OnEnable()
        {
            // 如果当前语言是阿拉伯语，排版调整右侧
            if (LocalizationManager.CurrSystemLanguage == LocalizationManager.CustomSystemLanguage.Arabic)
            {
                if (_text)
                {
                    if (_text.alignment == TextAnchor.LowerLeft)
                    {
                        _text.alignment = TextAnchor.LowerRight;
                    }
                    else if (_text.alignment == TextAnchor.MiddleLeft)
                    {
                        _text.alignment = TextAnchor.MiddleRight;
                    }
                    else if (_text.alignment == TextAnchor.UpperLeft)
                    {
                        _text.alignment = TextAnchor.UpperRight;
                    }
                }
                else if (_textMeshProUGUI)
                {
                    if (_textMeshProUGUI.horizontalAlignment == HorizontalAlignmentOptions.Left)
                    {
                        _textMeshProUGUI.horizontalAlignment = HorizontalAlignmentOptions.Right;
                    }
                }
                else if (_textMeshPro)
                {
                    if (_textMeshPro)
                    {
                        _textMeshPro.horizontalAlignment = HorizontalAlignmentOptions.Right;
                    }
                }
            }
        }
    }
}